import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;

public class TabFrequence extends ArrayList<CaracFrequence> {

	private static final long serialVersionUID = 1L;
	private BufferedReader br = null;
	private CaracFrequence[] staticTabConversion = new CaracFrequence[65536];	

	public CaracFrequence[] getStaticTabConversion() {
		return staticTabConversion;
	}

	public TabFrequence(File file) {
		try {
			br = new BufferedReader(new FileReader(file));
		} catch (FileNotFoundException e) {
			System.out.println(e.getMessage());
		}

		this.creerTableFrequences();
	}

	public TabFrequence() {
	}

	
	public void creerTableFrequences() {
		int c;
		try {
					
			
			while ((c = br.read()) != -1) {
				if (staticTabConversion[c] == null){
					CaracFrequence character = new CaracFrequence(c);
					staticTabConversion[c]= character;
					this.add(character);
				}else{
					staticTabConversion[c].incFrequence();
				}				
				//int index = this.indexOf(new CaracFrequence(c));
				//if (index != -1) {
				//	this.get(index).incFrequence();
				//} else {
				//	this.add(new CaracFrequence(c));
				//}
			}
		} catch (IOException e) {
			System.out.println(e.getMessage());
		}

		Collections.sort(this);
	}

}
